//
//  myFriendController.m
//  Focus
//
//  Created by dlios on 14-11-10.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "myFriendController.h"
#import "myFriendCell.h"
#import "UIImageView+WebCache.h"
#import "Friend.h"
#import "SinaViewController.h"
@interface myFriendController ()

@end

@implementation myFriendController
-(void)dealloc{
    [super dealloc];
    [_array release];
    [_table release];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        //        self.array = [NSMutableArray array];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatTable];
    //创建view
    UIView *down = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height - 48, 320, 40)];
    down.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:down];
    [down release];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 5, 40, 30);
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:@"circle_icon_quit.png"] forState:UIControlStateNormal];
    [down addSubview:button];
    
}
-(void)creatTable{
    self.table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height) style:UITableViewStylePlain];
    _table.dataSource = self;
    _table.delegate = self;
    [self.view addSubview:self.table];
    [_table release];
    //注册cell
    [_table registerClass:[myFriendCell class] forCellReuseIdentifier:@"friend"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [self.array count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    myFriendCell *friend = [tableView dequeueReusableCellWithIdentifier:@"friend"];
    Friend *fri = [self.array objectAtIndex:indexPath.row];
    [friend.myImage sd_setImageWithURL:[NSURL URLWithString:fri.profileImage]];
    friend.name.text = fri.name;
    
    return friend;
    
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SinaViewController *sina = [[SinaViewController alloc]init];
    Friend *friend = [self.array objectAtIndex:indexPath.row];
    sina.myid = friend.idNum;
    [self presentViewController:sina animated:YES completion:^{
        
    }];
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}
#pragma mark 按钮点击事件
-(void)buttonAction:(UIButton *)sender{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
